package com.guo.boot.study.thread;

/**
 * @Auther Heart Guo
 * @Date 2021/12/23-14:59
 */
/*
    测试守护线程

* */
public class TestDaemon {
    public static void main(String[] args) {
        Daemon daemon = new Daemon();
        You2 you2 = new You2();

        Thread thread = new Thread(daemon);
        thread.setDaemon(true); // 默认为false,表示是用户线程，正常的都是用户线程

        thread.start();//守护线程启动

        new Thread(you2).start();
    }
}

//守护
class Daemon implements Runnable{
    @Override
    public void run() {
        while (true){
            System.out.println("一直守护！");
        }
    }
}


//你
class You2 implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 36500; i++) {
            System.out.println("happy");
        }

        System.out.println("======goodbye word========");
    }
}